import java.util.Arrays;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 04 - 18
 * Time: 12:07
 */
//冒泡排序(升序排序)
public class test2 {
    public static void bubbleSort(int[] arr1) {
        for (int i = 0; i < arr1.length - 1; i++) {
            boolean flag = false;
            for (int j = 0; j < arr1.length - 1 - i; j++) {
                 if(arr1[j] > arr1[j + 1]) {
                     int tmp = arr1[j];
                     arr1[j] = arr1[j + 1];
                     arr1[j + 1] = tmp;
                     flag = true;
                 }
            }
            if(flag == false) {
                break;
            }
        }
    }
    public static void main(String[] args) {
        int[] arr1 = new int[]{98, 1, 456, 4, 5};
        bubbleSort(arr1);
        System.out.println(Arrays.toString(arr1));
    }
}
